package com.bignerdranch.android.time;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private int recLen = 60;
    private TextView text;
    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {

            if(recLen == 0) {

                handler.removeCallbacks(runnable);

            }else{
                text.setText("" + recLen--);
                handler.postDelayed(this, 1000);
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        handler.postDelayed(runnable, 1000);
    }

    private void initView() {
        text = (TextView) findViewById(R.id.text);
    }
}
